﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Xeml.Document;
using System.Collections.Generic;
using Mpi.Common.Collections;
using System.ComponentModel;
using Mpi.Common;
using Xeml.Document.Contracts;
using System.Linq;
using System.Data.SqlClient;
using Xeml.SQLDataProviders;

namespace Test_MySQLDataProvider
{
    /// <summary>
    ///This is a test class for MySQLDataProviderTest and is intended
    ///to contain all MySQLDataProviderTest Unit Tests
    ///</summar>y
    [TestClass()]
    public class Test_MySQLDataProvider
    {
        public TestContext testContextInstance { get; set; }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for MySQLDataProvider Constructor
        ///</summary>
        [TestMethod()]
        public void MySQLDataProviderConstructorTest()
        {
            MySQLDataProvider target = null;
            try
            {
                target = new MySQLDataProvider();
            }
            catch{}
            Assert.IsNotNull(target);
        }

        [TestMethod()]
        public void CredentialsTest()
        {
            MySQLDataProvider target = new MySQLDataProvider();
            Assert.AreEqual(Xeml.Sampling.ConnectResult.Success, target.TestCredentials("mssql", "mssql"));
        }

        /// <summary>
        ///A test for QueryData
        ///</summary>
        [TestMethod()]
        public void QueryDataTest()
        {
            //MySQLDataProvider target = new MySQLDataProvider();
            //List<SidMapping> samples = new List<SidMapping>();
            
            //SidMapping s = new SidMapping(1);
            //s.ForeignKeyMap.Add("Experiment", "10047if_28");
            //s.ForeignKeyMap.Add("Chromatogram", "10034if grasp vine2009");

            //KeyKeyValueCollection<string, int, object> expected = null; // TODO: Initialize to an appropriate value
            //KeyKeyValueCollection<string, int, object> actual;
            //actual = target.QueryData(samples);
            //Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for SupportsAutoMapping
        ///</summary>
        [TestMethod()]
        public void SupportsAutoMappingTest()
        {
            MySQLDataProvider target = new MySQLDataProvider();
            Assert.IsTrue(!target.SupportsAutoMapping);
        }

        [TestMethod]
        public void ForeignKeyListTest()
        {
            MySQLDataProvider target = new MySQLDataProvider();
            Assert.IsTrue(target.ListForeignKey().Contains("Experiment"));
            Assert.IsTrue(target.ListForeignKey().Contains("Chromatogram"));
        }

        /// <summary>
        ///A test for FilterKeyValues
        ///</summary>
        [TestMethod()]
        public void FilterKeyValuesTest()
        {
            MySQLDataProvider target = new MySQLDataProvider();
            target.AuthenticationRequest += (object sender, Xeml.Sampling.AuthenticationRequestEventArgs e) => {e.Cancel = false;};
            Dictionary<string, string> filter = null;

            string key = "Experiment";
            Assert.IsTrue(target.FilterKeyValues(key, filter).Count() > 0);

            key = "Chromatogram";
            Assert.IsTrue(target.FilterKeyValues(key, filter).Count() > 0);

            filter = new Dictionary<string, string>();
            filter.Add("Experiment", "10013if ulrike glaubitz-ellen zuther rice -130");
            filter.Add("Chromatogram", "10013if_10");

            key = "Experiment";
            Assert.IsTrue(target.FilterKeyValues(key, filter).Count() > 0);

            key = "Chromatogram"; 
            Assert.IsTrue(target.FilterKeyValues(key, filter).Count() > 0);
        }
    }
}
